<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>仓库</title>
</head>
<body>
<style type="text/css">
    .pro-img{
        border-radius: 3px;
        border: 1px solid #c4c4cd;
        padding: 3px;
    }
</style>
<script>
    $(function () {
        $("tboby tr").addClass("datagrid-row");
        $("#rdg").datagrid({
            onLoadSuccess:function (data) {
                $("a[name='details']").linkbutton({
                    width:30,iconCls:'icon-my_detail',plain:true
                });
                $("a[name='delete-one-repository']").linkbutton({
                    onClick: function () {
                        var rowId = $(this).attr("id").substring(4);
                        $.messager.confirm("继续删除提示", "确定要删除选定的仓库吗？", function (a) {
                            if (a) {
                                $.post("repository-del", {rowsId: rowId}, function (r) {
                                    if (r.success) {
                                        $.messager.alert("SUCCESS", "删除成功！", "info");
                                        $("#rdg").datagrid({
                                            url:'allRepositoryPaged',
                                            method:'post'
                                        });
                                        $("#rdg").datagrid("reload");
                                    } else {
                                        $.messager.alert("Failed", r.message, "error");
                                    }
                                });
                            }
                        });
                    },
                    width:30,iconCls:'icon-my_delete',plain:true
                });
                $("a[name='edit']").linkbutton({
                    width:30,iconCls:'icon-my_edit',plain:true
                });

            }
        });

        $("#reloadAllRepository").linkbutton({
            onClick:function () {
                $("#rdg").datagrid({
                    url:'allRepositoryPaged',
                    method:'post'
                });
                $("#rdg").datagrid("reload");
            }
        });
        //删除选中的分类(批量删除)
        $("#repository-del-btn").linkbutton({onClick:function (){
                var rowsId = "";
                var rows = $("#rdg").datagrid('getSelections');
                if(rows.length>=1){
                    $.messager.confirm("继续删除提示","确定要删除选定的这些仓库吗？",function (t) {
                        if(t){
                            for(var i =0; i<rows.length;i++){
                                if(i==0){
                                    rowsId=rowsId+rows[i].rid;
                                }else {
                                    rowsId=rowsId+","+rows[i].rid;
                                }

                            }
                            $.post("repository-del",{rowsId:rowsId},function (r) {
                                if(r.success){
                                    $.messager.alert("SUCCESS","删除成功！","info");
                                    $("#rdg").datagrid({
                                        url:'allRepositoryPaged',
                                        method:'post'
                                    });
                                    $("#rdg").datagrid("reload");
                                }else{
                                    $.messager.alert("Failed",r.message,"error");
                                }
                            });
                        }
                    });

                }else{
                    $.messager.alert("错误信息","未选中行！！！",'warning');
                }
            }});
    });
    function format(value,row,index){
        var str='<a id = \"'+"rShow"+row.rid+'\" name="details" href="#" onclick="createDialogHut(\'detilsRepository'+row.rid+'\',\'仓库详情\',\'to-form-repository-details\','+row.rid+')" class="easyui-linkbutton edit-btn"></a>'+
            '<a id =\"'+"rDel"+row.rid+'\" name="delete-one-repository" href="#"  class="easyui-linkbutton edit-btn"></a>'+
            '<a id = \"'+"rUpdate"+row.rid+'\" name="edit" href="#" onclick="createDialogHut(\'editRepository'+row.rid+'\',\'修改仓库信息\',\'to-form-repository-update\','+row.rid+')" class="easyui-linkbutton edit-btn"></a>';
        return str;

    }
    function formatR(value,row,index) {

        return'<b style="font-size:15px;color:orangered;">'+value+'</b>';
    }

</script>
<div class="easyui-layout" data-options="border:false,fit:true">
    <div data-options="region:'center',border:false">
        <table id="rdg" class="easyui-datagrid table-chance" style="width: auto;" data-options="fit:true,striped:true,height:350,fitColumns:true,
   autoRowHeight:true,nowrap:false,pagination:true,toolbar:'#tools-repository',
pageList:[5,10,15,20],pageSize:10,url:'allRepositoryPaged',method:'post',scrollbarSize:0">
            <thead>
            <tr class="datagrid-header-row">
                <th data-options="field:'code',width:5,align:'center',checkbox:true">编码</th>
                <th data-options="field:'rid',width:10,align:'center'">仓库ID</th>
                <th data-options="field:'rname',width:20,align:'center'" formatter="formatR">仓库名称</th>
                <th data-options="field:'raddress',width:20,align:'center'">仓库地址</th>
                <th data-options="field:'manager',width:20,align:'center'" formatter="format">操作</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
        <!--工具栏-->
        <div id="tools-repository" style="height:10%;">
            <a href="#" onclick="createDialog('newRepository','新建仓库','to-form-repository-add')" class="easyui-linkbutton" data-options="iconCls:'icon-mini_add2',plain:true">新建仓库</a>
            <a href="#" id="repository-del-btn" class="easyui-linkbutton" data-options="iconCls:'icon-my_delete',plain:true">批量删除</a>
            <a  id="reloadAllRepository" class="easyui-linkbutton" data-options="iconCls:'icon-my_search',plain:true">查询所有</a>

            <input id="repository-Search" class="easyui-searchbox" style="width: 35%;" data-options="searcher:function(value,name){
           $('#rdg').datagrid({
            url:'queryByrnameOrraddressMh',
            method:'post',
            queryParams:{q:value}
            });
            $('#repository-Search').searchbox('clear');
            $('#rdg').datagrid('reload');
           },prompt:'模糊查询仓库名称和地址'"/>
            <%--<a href="#" onclick="createDialog('hlQueryRepository','高级查询仓库','to-form-repository-highLevel')" class="easyui-linkbutton">高级查询</a>--%>
        </div>
    </div>
</div>
</body>
</html>

